package com.uuuo.rxjava1;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Subscriber;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void showMsg(String str) {
        Log.w("*********1111********", str);
    }

    public void test(View view) {
        Observable.interval(5, TimeUnit.SECONDS)
                .take(5)
                .subscribe(new Subscriber<Long>() {
                    @Override
                    public void onCompleted() {
                        showMsg("Interval onCompleted");
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onNext(Long aLong) {
                        showMsg(aLong + "");
                    }
                });
    }
}
